package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareUserInfoEntity;
import com.sgb.knowledgeshare.view.fragment.ShareMineFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ShareMineModel extends ViewModel {
    ShareMineFragment fragment;
    public void setActivity(ShareMineFragment shareMineFragment) {
        fragment = shareMineFragment;
    }
    /**
     * 获取当前用户信息
     */
    public void getUserHomePage(String userNo) {
        Map map = new HashMap();
        map.put("userNo",userNo);
        DialogHelper.showProgressDialog(fragment.getActivity(),null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getUserHomePage(map).enqueue(new ICallBack<BaseEntity<ShareUserInfoEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ShareUserInfoEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    fragment.setUserData(data.getData());
                }else {
                    fragment.setUserData(new ShareUserInfoEntity());
                }
            }
        });
    }


}
